package com.qf.openapi2204.common.utils;

import com.qf.openapi2204.common.vo.ResultVo;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * AI写的 工具类
 * 实现java对象转换成map
 */
public class ObjectToHashMapConverter {
    public static HashMap<String, Object> convert(Object object) throws IllegalAccessException {
        HashMap<String, Object> map = new HashMap<>();
        Field[] fields = object.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            map.put(field.getName(), field.get(object));
        }
        return map;
    }

    public static void main(String[] args) throws IllegalAccessException {
        ResultVo resultVo = new ResultVo(1, "ok", "hello");
        Map<String, Object> convert = convert(resultVo);
        System.out.println(convert);
    }
}
